{include file="public/_meta" /}
<body>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <script src="__STATIC__/tinymce/tinymce.min.js"></script>
    <script>
        tinymce.init({
            selector: '#mytextarea1'
        });
        tinymce.init({
            selector: '#mytextarea2'
        });
        tinymce.init({
            selector: '#mytextarea3'
        });

    </script>
    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">配置列表</h4>
                                </div>
                            </div>


                            <div class="card-body">
                                {volist name="infos" id="vo"}
                                <div class="d-flex">

                                    <div class="flex-1 ml-3 pt-1">
                                        <h6 class="text-uppercase fw-bold mb-1 {if condition="$vo.status eq 1"}font-success{else/}font-error{/if}">{$vo._value} <span class="text-warning pl-3">

                                         {if condition="$vo._key eq 'show_clue_day'"}
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="number" name="daynum" class="layui-input" placeholder="天数"
                                                   value="{$vo.extra}">
                                            <button type="button" class="layui-btn" onClick="save_day(this,'{$vo.id}')">保存</button>
                                        </div>
                                    </div>
                                    {/if}

                                        {if condition="$vo._key eq 'landingpage_text1' "}
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <textarea id="mytextarea1" name="landingpage_text1" value="" >{$landingpage_text1}</textarea>
                                            <button type="button" class="layui-btn" onClick="save_text(this,'{$vo.id}', 1)">保存</button>
                                        </div>
                                    </div>

                                    {/if}
                                        {if condition=" $vo._key eq 'landingpage_text2'"}
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <textarea id="mytextarea2" name="landingpage_text2">{$landingpage_text2}</textarea>
                                            <button type="button" class="layui-btn" onClick="save_text(this,'{$vo.id}', 2)">保存</button>
                                        </div>
                                    </div>

                                    {/if}
                                        {if condition=" $vo._key eq 'landingpage_text3'"}
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <textarea id="mytextarea3" name="landingpage_text3">{$landingpage_text3}</textarea>
                                            <button type="button" class="layui-btn" onClick="save_text(this,'{$vo.id}', 3)">保存</button>
                                        </div>
                                    </div>

                                    {/if}

                                        {if condition=" $vo._key eq 'send_sms_time'"}
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" class="form-control" name="send_sms_time" id="times" value="{$vo.extra}" placeholder="时间段" autocomplete="off">
                                            <button type="button" class="layui-btn" onClick="save(this, 10)">保存</button>
                                        </div>
                                    </div>

                                    {/if}
                                                    {if condition="$vo.status eq 1"}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_stop(this,'{$vo.id}')" class="btn btn-link btn-danger" data-original-title="停用">
                                                        <i class="fa fa-toggle-on"></i>停用
                                                    </button>

                                                    {else/}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_start(this,'{$vo.id}')" class="btn btn-link btn-success" data-original-title="启用">
                                                        <i class="fa fa-toggle-off"></i>启用
                                                    </button>
                                                    {/if}
                                        </span></h6>
                                        <span class="text-muted">{$vo.remark}</span>
                                    </div>

                                </div>
                                <div class="separator-dashed"></div>
                                {/volist}

                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script src="__STATIC__/layui/layui.js"></script>
<script type="text/javascript">
    var SCOPE = {
        'status_url':"{:url('system_config/status')}",
        'delete_url':"{:url('system_config/delete')}",
        'item_url':"{:url('system_config/edit')}",
        'add_url':"{:url('system_config/save')}",
        'save_day':"{:url('system_config/save2')}",
    };

    laydate.render({
        elem: '#times'
        ,type: 'time'
        ,range: true
    });


    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{
                _key:{
                    required:true,
                    minlength:2,
                    maxlength:30
                },
                _value:{
                    required:true,
                    minlength:2,
                    maxlength:30
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                if(commitStatus==true){
                    return false;
                }
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus==true
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        $("input[name='id']").val(id);
        document.getElementById('form-modal').reset();
        $(".fw-mediumbold").text('添加');
    }

    function edit_item(id) {
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('编辑');
                    $("input[name='id']").val(res.data.id);
                    $("input[name='_key']").val(res.data._key);
                    $("input[name='_value']").val(res.data._value);
                    $("#remark").val(res.data.remark);
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }



    /*机构-删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.delete_url,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg('删除机构成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    /*机构-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:2,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已停用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }

    /*机构-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已启用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }

    /*保存天数*/
    function save_day(obj,id){

            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.save_day;
            var day=$('[name="daynum"]').val();
            $.post(url,{_value:day,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('保存成功',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });



    }

    /*保存富文本*/
    function save_text(obj,id,type){
        if (type == 1) {
            var content = tinymce.get('mytextarea1').getContent();
        } else if (type == 2) {
            var content = tinymce.get('mytextarea2').getContent();
        } else if (type == 3) {
            var content = tinymce.get('mytextarea3').getContent();
        }

        //此处请求后台程序，下方是成功后的前台处理……
        var url = SCOPE.save_day;
        $.post(url,{_value:content,id:id},function(data){
            if(data.code == 1001){
                layer.msg('保存成功',{icon: 1,time:1000},function(){
                    window.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon: 2,time:1000});
            }

        });



    }

    function save(obj_id,id){

        //此处请求后台程序，下方是成功后的前台处理……
        var url = SCOPE.save_day;
        var info=$(obj_id).prev().val();
        $.post(url,{_value:info,id:id},function(data){
            if(data.code == 1001){
                layer.msg('保存成功',{icon: 1,time:1000},function(){
                    window.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon: 2,time:1000});
            }

        });



    }

</script>
</html>




























